fopen, fwrite, and fclose are all C functions. There may be a way to enable them in perl, and in fact Perl just maps its own functions back to the C calls. However, they need to be changed to the appropriate perl functions.
If you change
fopen( FH, "$_" ) to open( FH, "$_" )
fwrite( FH...