If you're piping to the script, then
you need to read the message from STDIN. So you'd
do something like this, although if you're doing something
spectacular, you'd want to modify this a bit :).
open OUT, ">>mail.out" or die "Can't open: $!";
print OUT while <STDIN>;
close OUT;
At least this is how it works on my system.