The user that apache/php runs under doesn't have the same PATH environment as a shell account.
Use the full pathname to the pg_dump program, e.g.:
<?
shell_exec('/usr/sbin/pg_dump -f /root/backupfolder/testfile.sql -h sourcedomain databasename');
?>
--ETA: If you are on a *nix system, type which pg_dump to find the full pathname.