Save a notebook through kernel

In my work, I am opening a notebook file, evaluating and writing commands to it through Mathematica Kernel. I want to save my results into a new file (notebook or pdf format). When I use NotebookSave[] option, the save dialog box appears and I am able to save it. But when I open it later, there seems to be an error and a message pops in that the file is corrupt.

What should I do now?

Does this always happen on your computer for even simple examples ending in NotebookSave?

If not, the next step is to probably come up with a minimal example of the problem. This means weeding out the changes to the notebook which don’t seem to cause the problem.