Write output to a file