The ask here is not to store the password as plain text in file, the reason is simple that anyone can get it from here and misuse.
I suggest you to use Encypt your passowrd using strong Encyption technique like sha-256 etc and then store that enrypted passowrd in the file.