Created one method for file writing