>>out=open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
You didn't error check this one, maybe there's a problem opening/writing to the file.

Run it under a debugger to find out more...