Implemented writing to file