If you are building a more complex feature, consider these approaches:

: Content-Disposition: attachment; filename="KingCode.txt"

: If users are downloading multiple .txt files, use a library to zip them together first. Stack Overflow

: Generate text on the fly and trigger a download without a server file.