Sauron raised and tamed them
Okay, I'm going to give this more thought than Peter Jackson did... :)
In LOTR, we learn that Sauron raised and tamed the fell beasts of the Nazgûl.
A creature of an older world maybe it was, whose kind, fingering in forgotten mountains cold beneath the Moon, outstayed their day, and in hideous eyrie bred this last untimely brood, apt to evil. And the Dark Lord took it, and nursed it with fell meats, until it grew beyond the measure of all other things that fly; and he gave it to his servant to be his steed.
We also know that Sauron is extremely powerful, even able to control the weather:
'I wonder if this is a contrivance of the Enemy,' said Boromir. "They say in my land that he can govern the storms in the Mountains of Shadow that stand upon the borders of Mordor. He has strange powers and many allies.' 'His arm has grown long indeed,' said Gimli, `if he can draw snow down from the North to trouble us here three hundred leagues away.' 'His arm has grown long,' said Gandalf.
So Sauron probably has the power and skill to raise and tame the were-worms (either by himself or by proxy). Since the worms themselves didn't do any fighting, we can assume they were unsuitable for combat. If they're anything like regular worms, they just like to dig, which is what they were used for in the movie.
Why would he do this?
Sauron orchestrated the attack on Erebor by Azog and Bolg's armies. Since it was a surprise attack, the ability of the were-worms to dig holes was useful for this. We can speculate that he raised the were-worms over the course of many years for this very purpose.
Why didn't Sauron ever use were-worms again?
He flees to Mordor after the White Council attacks Dol Guldor, and the orc army that oversaw the were-worms was destroyed. So, he would have lost contact with the were-worms used in the battle.
Maybe it was impossible to find them again, and it would take too long to raise new ones.
How did the orcs control where the were-worms moved?
We're never shown this, of course, but with some imagination you can think of some ways. For example, maybe the worms could be trained to seek a certain sound. So if you took some of the drummer trolls and had them play a certain rhythm, the were-worms would move towards the sound.