BUG [scripting] : File API and After Effect File Security Preference
To recreate (*), run this script a first time to create a test file on your desktop with AE security off (writing files allowed) :
var f = new File( "~/Desktop/test_write.txt" );
Once the file is created, turn AE security ON (writing files disabled) and run the script again.
An alert is sent, but the file is now ... EMPTY.
AE threw the error a touch too late :)
... that is, after the file has been open for writing, hence effectively emptied, and not before, as it should be.
This is a big bug and should be addressed (and it's surprising nobody ever complained about it in so many years).
(*) Given that bug reports are now public: only if you know a minimum about scripting.