Is it 100% necessary to store it as a *.txt file? Will the user need / want to have access to this file? If not, try using Local Storage to store the string that you would have stored in the *.txt.
Otherwise, you'll have to rely on NWJS (so desktop-only, there probably won't be a mobile solution for this). It can read and write text files effectively.