I have an overall model I use on a majority of playthroughs for farming Truffle Worms. There are more advanced and efficient designs for Truffle Worm farms out there, but it can require setting up wiring and using traps obtained from the Lihzahrd Temple.
Basically I pick out an area of the Cavern layer, clear the blocks out of it, and build a series of Mud Block walkways divided by 3 spaces, so that you can walk in all the sections. (Then seed them with Mushroom Grass Seeds) Then in the center of the walkways, I have a vertical pit designed to catch truffle worms that wonder into them.
To get Truffle Worms to spawn, I have my character wait on a platform above so that the camera does not have the mud platforms in view. Here's a picture to illustrate what I mean:
Recommended items for this setup also include the Rare Lifeform Analyzer, or the PDA/Cell Phone, and a Golden Bug Net. The Lifeform Analyzer will allow you to see if a Truffle Worm has spawned below while you have your character on the above platform.
This can be done without the Golden Bug Net, but the Golden Bug Net has fast autoswing and a wider capture range compared to the basic Bug Net.
Overall this isn't a perfect farm as other enemies still spawn and have a chance to kill the Truffle Worms even if one spawns. It does require manual moving to sometimes kill enemies as they can interfere with Truffle Worm Spawning. But it is fairly easy to setup and is efficient enough to give a fair amount of worms to capture. Generally I average getting 2-4 Truffle Worms every 10 mins with this general setup.