I don't think it was a worm, as Tracie said if it was in the urate it was probably just something that looked like a "string"...are you sure that he is a male? If so, it could have been a sperm plug that came out during his bowel movement, they are long and stringy looking.
I have to recommend that you switch up his diet ASAP, as first of all, they shouldn't ever, ever be fed any "freeze-dried" insects at all. They have no nutritional value at all, and they contain 0 moisture, and dragons need live insects to not only get the nutrition they need, but also they get most of their
hydration from their fresh greens/veggies and from their live insects. Also, they do tend to have a lot of impactions and bowel movement problems when they eat freeze-dried insects, because it's essentially like feeding him really hard cardboard, and this is probably part of the reason his bowel movements are weird. They often cause really bad bowel impactions and obstructions as well. There's just nothing good about them at all.
If he's an adult it's best to feed him a nice big, always fresh salad of healthy greens and veggies every day, along with a few healthy, gut-loaded (with the same fresh greens/veggies), live staple insects, such as crickets, roaches, Phoenix worms/BSFL, or Silkworms. The pellets are unfortunately not at all a replacement for live, gut-loaded insects or fresh greens and veggies, and most of them won't eat enough of them for it to make a difference. And the ZooMed pellets are not a good choice, nor are any of the Flukers pellets, most of which contain freeze-dried insects. Do not pick a pellet, if you're going to offer him pellets, that contains any dead insects in it. The 2 healthiest pellet choices are the RepCal mult-colored, juvenile pellets and the Mazuri natural pellets that come in a bag, but again, I don't recommend them as a replacement for live, gut-loaded insects.