Added a function to output to a file