You don't have to change the script in any way.
The variables, like _barn, in the script are local to the script and have nothing to do with the object in the game named 'barn'.
So you can call the destination anything you like, you can feed just a position into it instead of a object and you don't need to change a thing in the script itself. You just execute the script by passing the desired destination, for example:
[[goat1,goat2,goat3,goat4,goat5],3,barn] execVM "herder.sqf"; //object called barn
[[goat1,goat2,goat3,goat4,goat5],3,shed] execVM "herder.sqf"; //object called shed
[[goat1,goat2,goat3,goat4,goat5],3,moon] execVM "herder.sqf"; //object called moon
[[goat1,goat2,goat3,goat4,goat5],3,[3613.83,3638.12,0]] execVM "herder.sqf"; //some position
[[goat1,goat2,goat3,goat4,goat5],3,position ((position player) nearestobject 5146)] execVM "herder.sqf"; //building with ID 5146
Also, if you want to have different kind of animals to go to a different locations you can execute several instances of the scripts, like:
[[goat1,goat2,goat3,goat4,goat5],3,barn] execVM "herder.sqf";
[[cow1,cow2,cow3],3,shed] execVM "herder.sqf";