Added test to ensure written files
Fixed file writing