in reply to writing formatted output to file

Perhaps the quickest solution is to just redirect STDOUT to file when you're running the script, eg.:
% perl myscript.pl > report.txt