I have this line in my perl script that sshes into a remote machine and execute a bash script:
system("ssh -t remotemachine /dir/dir/bashscript");
some commands 2 >> error.txt
Use the full path for the capture file.
some commands 2 >> /dir/dir/error.txt
Otherwise the file will be created in the users $HOME if it exists.