fixed race condition.  Close on BufferedWriter now doesn't return until underlying writer is closed, ensuring a proper flush before the app exits