Implementation of writing data to file