Added a file writing function and test.