added a write to file function