How to restore wrongly edited + wrongly saved TextEdit file?
TextEdit (and other apps that use the autosave system) will automatically save snapshots of documents at various times (e.g. when they're opened but before they're changed). Reopen the document in TextEdit, then from the File menu choose Revert To. It'll have a submenu that might have a relevant snapshot listed that you can choose directly. If not, choose Browse All Versions. You'll get a Time-Machine-like history on the right side of the screen, and you can look for the latest good version, then when you find what you want click Restore.

See this OWC/MacSales article, this one at OS X Daily, and this Apple support guide for more details and options.