You cannot just pass a file name to cmd and expect it to read the file, parse it, transmit it and execute it. See Net::SSH::Perl. In particular, note that each string passed to cmd is executed in an independent session. The easiest solution to your proposal is to copy the script to the remote server, so it can be invoked with a single command. Something along these lines could also function for you:
open(FILEHANDLE, '<test.sh');
my @file = <FILEHANDLE>;
close FILEHANDLE;
ssh->cmd(join ';', @file);
|