What you are describing is not ascarias. A. lubricoides or even a zoonotic version are very very large and thick - e. up to 1/2 cm wide to 20 to 30 cm long and reside in the large bowel.
Whipworm is very hard to kill and resides in the cecum - and is thinner but 6 to 8 cm long with an obvious thin section that 'whips' around for motility.
The 5 cm long and thin is not descriptive of usual intestinal worms save hookworm which reside in the small intestine and usually dont see an adult in the stool. While hook worm can have tissue phase in its cycle -- tends not to disseminate distantly (ie to scalp) and be active. The tissue phase is to form cysts which are dormant until the worm burden decreases and then they are recruited (become active).
Last in the size and appearance you give is Trichostrongylus, which is typical a livestock parasite - but well documented in man. Many species are completely resistant to anti helminths - esp albendazole. Its size can be thinnish and 5 to 7 cm in length for some species The adults live in the upper intestines but have been found in the stool - AND they are most probably auto-innoculating like Strongyloides. Very little is actually studied on these in man and can't find a lot in the Vet literature - ie. is there a dessiminated skin phase and so on.
Try the IVM with a different benzimidazole like oxybendazole (horse paste again) in combo and try to add pyrantel pamoate (hard to take) but the synergistic effect is very good and effective. In other words these meds don't work so well alone and need to combined to get good results.
Also, add neem oil to your regimen. 1 1/2 tsp cold pressed oil to grapeseed or almond oil or such and slug back and chase with milk. This is an Ayurvedic therapy with years of proven antihelminth acitivity. Take on empty stomach and then eat about 45 min later. Also for the other meds -- take with oil or some fatty item - about 40 gms to enhance absorption and bioavailability.
So -- the creature you describe sounds most like Trichostrongylus columbiea or axie - (sp) which are highly resistent to benzimindazoles and IVM - and its analogues. But, IVM combined with pyrantel pamoate and the Ayurvedic herbs may help. Is okay to take DE - but make sure that you are al least 2 hours out on either side of eating. It can interfer with absorption of meds and other herbs.
You may very well also have Strongyloides which usually (the adults) won't show u in the stool as they reside in the upper intestine too. The human species is stercoralis - but pets have this and other species that man can get.
They can have a cutaneous manifestation and are tough to eradicate as the L3 larvae are auto-infective. They will reenter the skin around the anus leaving a rash or inside the intestinal walls.
The thing on your scalp may not be related to any of these (not known in the their life cycles). However, is it possible that you acquired filaria (Dirofilaria genus is a zoonotic and more and more human infections are being reported).
An adult can take up residence on the scalp and cause the sxs you describe. IVM is purported to kill off the microfilaria (which produce sxs) and sterilize the females for several months so they do not release more microfilaria into the blood stream (read up on subcutaneous filaria to understand its life cycle and sxs).
The intestinal worm you describes morphology according the size you give has to be either hook worm or Trichostrongylus. Both of which are incurable but can knock back the adult population and reduce the worm burden. Will have to engage in treatment probably once a month - maybe can get away with every two months - and use the herbs daily.
BTW -- engage the IVM 200 mcg/kg, oxybendazole 800mg, pyrantel pamoate what is recommended together for a 4 day blitz each month or two.
Add 200 mg doxycycline or minocycline because of the doxy shortage twice daily if you can take the 200mg bid otherwise 100 twice daily with food on a daily basis.