Writes the output to a data file.

Also created a function for the header and footer.