How can I redirect the printed output to an output file?