Incase someone else has the same situation. You cannot do this. You cannot change the Template address in code its is read-only. I have opened a support call with microsoft and they have confirmed that it cannot be done.
You can put a relative URL in the template address but this is replace with a fully qualified URL once the form is saved.
There are 2 ways i can see to fix the issue. Use one authentication type. For me this beens Forms authentication which is messy to setu for users that could have used windows accounts.
Or
We have had a thought of writting an event handler for MOSS that changed the template address to be relative after each form has been saved. Not sure how easy this is yet but is is something worth thinking about.