I run your code on my linux server.
("mm.txt" ,"this is the content")
For the first time, mm.txt is created and the content of mm.txt is all right.
For the second time, I got the error message:
"Error in file system on line 21 could copy file!!" TWICE.
mm.txt is exists.
mm.txt2 and mm.txt3 are both created, but they are empty , because while copying for mm.txt3 , mm.txt2 is not exists.
while copying for mm.txt2, mm.txt1 is not exists.
mm.txt1 is created and the content of mm.txt1 is right.
if (copy($file.$i,$file.$z)){
should be if (!copy($file.$i,$file.$z)){