Write out to file

Included functionality for writing to a file as well as stdout.