For those wondering, we didn't die mostly due to a well-placed Disintegrate. My "stick an immovable rod in its innards" was disappointingly low damage.
For those wondering otherwise, our best plan involved turning it into a regular worm, using an immovable rod with a hole drilled through the length of the staff, clicking the rod, then dispelling polymorph.
My party fought a purple worm recently. It devoured the cleric. Then the sorcerer used polymorph on it to turn it into a frog, which caused the cleric to get squeezed out of it like toothpaste in a tube and shot out of it and collided with the cavern ceiling, taking 'fall' damage. Then the cleric used divine intervention (successfully)... as a divine avatar they swooped down and crushed the frog between their hands, releasing a tidal wave of venemous worm viscera to wash over everyone causing them to take massive poison damage. Great fun :D
In terms of your plan, drilling a hole in the rod may cause it to lose function. Also a general rule about polymorph is that there needs to be room for the transformation, and a general rule for invalid creature placement is that creatures take a small amount of force damage and are moved to the closest available space. As your DM I'd probably say you couldn't end polymorph early while it's in the rod, and if you lost concentration or the duration expired, it would be shunted next to the rod and take 2d10 force damage.
Actually what I'd like to do is have the worm trapped in the rod, make you believe it died, and the next time you used it the worm would appear.