Changed output function to allow sending the output to a file