How do you create a txt file in the games folder during gameplay?

Heya! So I'll do my best to explain what I'm asking. If you've ever played OneShot you know the game likes to mess with your computer. In one section, you need a password to open a chest, but the password is nowhere in the game. Instead, the game generates a txt files directly onto your computer that contains the code. I want to do something similar with my game, almost make it seem like the game is 'talking' to the player through these txt files. However I have no idea where to even start. Specifically, I want it so when you interact with certain events, the game generates a txt file directly into the game folder (I.E where the executable is located). Does anyone know if there's a plugin or script command that could help me out with this?
Edit: Never mind, it's five lines of code you can find here

Semi-related:
Personally I am somewhat interested in this myself, but for saving a generated bitmap as a file. For example, I generate a character with SRD's character creator in game then export the output as a .png in the game directory (or just overwriting an existing .png instead of creating a new one)
Edit: Never mind, it's five lines of code you can find here

Semi-related:
Personally I am somewhat interested in this myself, but for saving a generated bitmap as a file. For example, I generate a character with SRD's character creator in game then export the output as a .png in the game directory (or just overwriting an existing .png instead of creating a new one)
This extracts text from the game but i want text that doesnt appear in the game to appear in a text file. I figured this out by using this code

const fs = require('fs')
let text1 = "(Input the text you want to appear in the file)"
let data = text1

// Write data in 'FileName.txt' .fs.write
File('FileName.txt', data, (err) => {
// In case of a error throw err.})
In addition to the above you could also use this plugin if you want to make things a little bit easier.
It basically does the same thing, but wrapped in a single script call.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-you-create-a-txt-file-in-the-games-folder-during-gameplay.173207/