I have/had a tiny one (if I still have it, I hope it is still tiny...) and it didn't leave the confines of its rock. It has/had a small hole, and when it is done finding mysis that float its way, it covers its hole opening w/ small stones. Crafty critters in deed.
I would guess that what the others have said is true, based on observing this one. Likely you found the worm while it was foraging, and it took refuge somewhere out of dire need, but has a nice home location somewhere in a choice piece of rock.
The only thing that I have in my tank that does not seem to claim a piece of tank as its home (even if that home changes every few weeks) is my clownfish that doesn't have an anemone. He just sleeps practically at the water's surface.