Added writing to output file