in reply to Net::OpenSSH mutliple commands

Net::OpenSSH (and actually also Net::SSH2 and Net::SSH::Perl) starts a new session for every command run, so the effects of operations as changing the working directory or setting environment variables do not persist between commands.

One way to overcome that is to join all the commands together:

$ssh->system("cd $dir && tar czf /tmp/file.tgz .");

In your case, you can also eliminate the scp_get step transferring the archive as it gets generated:

$ssh->system({stdout_file => '/tmp/file.tgz'}, "cd $dir && tar czf - . +");