write get.ElementByClass() from nested div to file

Yeah, don't call document.getElementsByClassName() multiple times. Also, what happens if the user types in something twice before the chatbot responds?

I would recommend you add a msg-bubble-user and msg-bubble-bot to your .msg-bubble element. Then loop through them, recording the transcript according to the class name, not the position:

document.querySelector(".msg-bubble").forEach(el=>{
    const speaker = el.matches(".msg-bubble-user") ? "You" : "Chatbot";
    const content = el.querySelector(".msg-text").textContent;
    thefile.writeline(`${speaker}: ${content}<br />`);
});

^untested

If your file is empty, add a console.log() call to see if you're getting the text you're expecting.