Most of the time you will see wormlike creatures when there is an excess of debris on the bottom related to overfeeding or inadequate gravel vac/water change schedule. They can be introduced in a variety of ways, but most likely this is completely harmless to your fish.
The treatment is to starve it(them) out by reducing feeding, increasing water changes and gravel vacs, and paying close attention to how much food gets consumed at feeding time, so there is little to nothing left over to sink to the bottom.
I think most aquarists at some point or another, me most definitely included, have had worms/nematodes at some time or another. Another notch on your belt, LOL