Type dispositions allow you choose the action the browser will take when you give it a file, it’s defined in rfc 2183 if you want to display the file in the browser you can output
print "Content-Disposition: inline; filename="$filename.$ext"n"
as apart of the file before the mime type and if you wish to force a download of the file use
print "Content-Disposition: attachment; filename="$filename.$ext"n"