If you use the latest version of Apache, you can build suExec with it, which will run your CGI scripts as the user you specify... and if you are running in a ~user directory, it will assume the uid and gid of that user.
After running into this problem, i wrote a program which you can install as setuid root in you php safemode exec dir. (defined in php3.ini) You then can do system() calls to this program to change the ownership of file, in a fassion such so that it shouldn't allow people to break the security of your box. You can get the program at http://srparish.net/scripts/chuid-1.0.tar.gz