Sometimes undo information can add a lot of space to your project. When I am working on very large projects and perform even simple operations such as amplify that affect the entire track(s) I sometimes close the project then reopen it - in that manner Audacity will return the unneeded space to the operating system.
Note also, that if an rc error code of 11 accompanies your “failed to write message” it could be due to a corrupt project database: Corrupt or Otherwise Broken Audacity Project Recovery