Thats because WordPress TinyMCE editor strips out the onclick attribute as it sees it as a possible risk. There are several solutions if you google “stop WordPress from stripping HTML”. If you’re using the Gutenberg block editor, the HTML Block is more forgiving and will ( probably ) allow it.
But… adding an onclick event in HTML is bad practice and should be avoided.
You’re better off adding an event listener in you JS eg.
const saveTextFile = document.querySelector('.save-button');
saveTextFile.addEventListener('click', saveTextAsFile);
Then add the save-button
class to your button e.g
<button class="save-button">Save Text to File</button>