I guess it is the pipe that is giving this problem. You might be getting the exit status of
"gzip -c > /usr/local/bin/database.gzip"
You might have to split the dump and gzip part into two.
use
`mysqldump -u root -ppassword database1 > ./dump.txt`;
if ($? == 0){
`gzip -9 ./dump.txt`;
}
else{
die "errored";
}