JSFiddle - React, Tailwind, and code Playground

HTML

<button id="withoutEmoji">without emoji
</button>
<button id="withEmoji">with emoji
</button>

JavaScript

function downloadFile(filename, text){
let element = document.createElement('a');
        element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
        element.setAttribute('download', filename);
        document.body.appendChild(element);
        element.click();
        document.body.removeChild(element);
}

document.getElementById("withoutEmoji").onclick = function(){
downloadFile('withoutEmoji.txt','This is a test without emoji');
}
document.getElementById("withEmoji").onclick = function(){ 
downloadFile('withEmoji.txt','This is a test with emoji 😀');
}