in reply to changing uid/gid in suid cgi script

Change groups before changing uid. Once you've dropped root permissions you're dropping the permission to modify your groups.
$GID = $new_gid; $EGID = "$new_gid $new_gid"; $UID = $new_uid; $EUID = $new_uid;
should work.