in reply to how can i open a new file with permission 0666 ?

You can open files with more control over the permissions with sysopen: sysopen(OUTFILE2, $full, O_WRONLY, 0666). Maybe other flags are necessary, but this should get you underway.

Arjen