added more detailed tracing of error when files can't be opened for writing