PrintWriter added to write output to a text file, comments added.