"Instinctive" is not always well defined. Earthworms have innate behaviors that serve them well. Tactile stimuli applied to the posterior end cause them to extend the anterior setae and contract their longitudinal muscles, thus moving forward. Anterior tactile stimuli cause extension of the posterior setae, flattening of the tail (in some species) and longitudinal muscle contraction, causing movement to the rear. The neural underpinnings of these behaviors are fairly well established.
I am unaware of any studies examining worms forming their body into hook shapes. If this is an innate, hard-wired response to being submerged, or being caught in flowing water, it might serve the adaptive purpose that you suggest. We must be careful in asserting a motive, though; if worms do this it is not likely that they are trying to save themselves, as they likely lack the neural machinery to imagine their impending demise.
Thanks for a good question!