Are you sure it doesn't write or the file content is overwritten by CDocument::OnSaveDocument(lpszPathName)?

But a breakpoint before the call to CDocument::OnSaveDocument(lpszPathName) and check the content of your file.