There might be Instances when you save a file and later on you realize that it is corrupted. There can be many reasons for this behavior to happen in SharePoint. One of the likely reasons would be that if you have code or libraries from another source which you paste on the SharePoint Designer and save it immediately.
If you happen to paste code from another source you have to wait for a while to allow the color coding to appear on the file. Once that appears you could safely click on the Save Button.
So, next time when you try to save a file in SharePoint Designer remember to wait for a while and then click on the Save Button 🙂