Added correct file mode to output file