Our Moodle installation was serving .txt files via file.php with an incorrect text/html MIME type instead of the correct text/plain MIME type. This was breaking the exercises from a new authoring tool we're trying out.
Adding .htaccess directives wasn't an option as the file request isn't handled by Apache. Moodle stores course files in a non-public directory, using file.php for access control.
After poking around the source code I got to line 829 of lib/filelib.php, where I saw that .txt files' MIME types are rewritten from text/plain to text/html when "filter all files" is active. A quick visit to Administration → Modules → Filters → Manage filters and changing the "Filter uploaded files" option from "All files" to "HTML files only" fixed the issue.
Don't forget to clear the browser's cache.