There is a thread I saw somewhere about random critters in peoples tanks. I can’t ID it, but to get rid of them I would suggest feeding less food. Because if you over feed there is leftover food for the worms to feast on.
I found black little worms in one of my tanks as well. It's hard to tell if yours was the same as mine but I wouldn't worry about it. I just fed Bourbon less and they vanished within the week.
Most worms that size aren't parasites either. It's also outside of the fish and I'm assuming it wasn't attached to the outside of them either. I'm sure that it's just fine but you'll definitely want to feed your fish less for a week or two in order to get rid of them.
I was finding some in one of my tanks a few months ago. If you're still seeing lots after you feed less and you don't want to dose the tank with anything, adding some cories did the job in a matter of days for me, and I haven't seen any worms since.
I only found the one I may have been a overdoing it a little just not sure if it was a fish killer or a pest come in from some other fish. I haven't found any more yet it may have been a one time thing.