added error handling to file opening and buffer flushing
added warning output for errors, updated description