Thanks to you both, yes, that was it!
In my other scripts, the addhost, etc and related scripts that do work, domain = argv0 is defined much lower in the code, reordering as suggested here has fixed it and it is now playing nice :)
Thanks again guys!