in reply to maintaining owner id

one thing you can do is use a group and sticky the dir that is the root of all created files.. for example:
mkdir /var/tmp/test chown youname:mygrp /var/tmp/test chmod 775 /var/tmp/test chmod g+s /var/tmp/test ls -la /var/tmp/test su - otheruser touch /var/tmp/test/newfile ls -la /var/tmp/test
as long as you set the umask in your script to force 775 for the group you will efectivly own those files...

-Waswas