It does not really matter where you call it. I am guessing you are missing some directx stuff that file_for_screen needs to work.(Or maybe it's an engine bug, some other thing)
try updating to latest directx to see if that works.
(does the small test script i posted gives the same error?)