That behavior makes me think it isn’t harmful, possibly a detritus feeder. If it isn’t a worm, maybe it is a tiny sea cucumber. Avoiding light and retracting are signs it is nocturnal, and most likely vulnerable to fish predation in daylight. Probably harmless. Try posting the pic to iNaturalist.