Why "Save File" dialog sometimes shows when changing language programmatically?

I’ve written a code which uses local and session cookie to store the language setting so that if the user had been to the site before, then I switch to previously used language content. Once in a while (I think it usually happens with a user’s first or second visit), that a “Save File” dialog would pop-up sometimes and asking to save an HTML file. I have no idea why it’s doing that because all I am doing is saving session and local data. Below is the code that I have in masterPage.js which switches language if needed and displays a Korean or English language content.

import {local, session} from 'wix-storage';
import wixWindow from 'wix-window';

$w.onReady(function () {
    // If multi-lingual is enabled AND ...
    // If data from local does not exists, then use browser language setting.
    // If data from local exists:
    //   If data from session does not exists, then use data from local.
    //   if data from session exists, then use the data from multilingual.currentLanguage
    if (wixWindow.multilingual.isEnabled) {
        const sessLangPref = session.getItem("tccLangPref");
        const locLangPref = local.getItem("tccLangPref");

        if (locLangPref === null) {
            if (wixWindow.browserLocale && wixWindow.browserLocale.toLowerCase().startsWith("ko")) {
                // Korean detected. Set current langugae to Korean.
                wixWindow.multilingual.currentLanguage = "ko";
                local.setItem("tccLangPref", "ko");
            } else {
                // Non-Korean detected. Set current language to English.
                wixWindow.multilingual.currentLanguage = "en";
                local.setItem("tccLangPref", "en");
            // Set session data with local data.
            session.setItem("tccLangPref", local.getItem("tccLangPref"));
        } else {
            if (!sessLangPref) {
                // Local data exists, but no session data, then use local data to set language
                wixWindow.multilingual.currentLanguage = locLangPref;
                session.setItem("tccLangPref", locLangPref);
            } else {
                // Local data exists, and session data also exists, then assume use changed setting.
                // If existing local/session data are different from new language setting, update them.
                if (locLangPref !== wixWindow.multilingual.currentLanguage) {
                    local.setItem("tccLangPref", wixWindow.multilingual.currentLanguage);
                if (sessLangPref !== wixWindow.multilingual.currentLanguage) {
                    session.setItem("tccLangPref", wixWindow.multilingual.currentLanguage);