in reply to Shell to Perl conversion
In your case, print to STDOUT instead of the $OUT file and print the HTTP header before your output
echo "Content-type: text/plain" echo [download]