Added functions to write current buffer to file.