writing error to file