what are worms doing in my tank?

Could be nematodes too. I had some and it sounds exactly like what you had. Im not sure what caused them to go away in my tank though.
 
I have had these too. I believe they are a harmless species of nematode. I would not worry about them at all.
 
AquariaCentral.com