as davorg mentioned, this would be a good solution.
just to remind you of two problems that may occur:
try putting Content-Disposition: infile; filename=$filename into the header if the browser
doesn't know, what filename it should choose for saving the file
binmode STDOUT; is usefull, if you transfer binary data