You have an error in your script - the command you're sending to the remote machine is not interpolated. You likely want:
$cmd="tar -czf - $rmt_dir";
Depending on how dire your error handling situation is, avoiding Perl might be the most convenient way to resolve your memory issues:
ssh -c "tar -czf - $rmt_dir" >backup.tar.gz
This will run the tar command remotely and output the created .tar.gz file directly to STDOUT, and on the local end will write the output directly into a file instead of buffering it locally in memory. You will need some error checking afterwards though.