Write data to file