Just an idea that may not be suitable in your particular case.
Investigate su and sudo. I have no idea how your server is setup, it can be complicated or impossible. Google and groups.google search for "sudo cgi" etc. Usually you need suexec running, so that cgi scripts get run as the user of the homedir. Sudo is usually preferred nowadays, since it is more restrictive(safer), where you specify what can be run , and by who, in a sudoers configuration file ( usually /etc/sudoers)