This is not the whole answer you are looking for, just some hints;
You need a cgi-wrapper that can execute a script as a different user. To do this as root is extremely risky, you really need to make sure the scripts are as secure as possible.
I would suggest to approach with a different track, keeping the e-mail users password files in a different location and execute the wrapper as another system user with access to these files only. Many of the shared-web-hosting solutions (control panels)out there do things like this, they have the wrapped scripts executed as the user of the main account, then all the mail for this domain is authenticated/fwd with content of these 'private' files.
Maybe looking for opensource control panel solutions will give some clues?
Good luck :)