Writing to a text file doesn’t introduce any direct attack vectors.
It is possible to write flawed code to write to a text file which introduces attack vectors (particularly if you accept a file name as user input).
Things you do with the text file later (such as making it public with certain content-types) might.
7
solved Can someone run malicious code while writing into .txt