Firstly, make sure that the directory you are writing into a) exists and b) has the right permissions to allow you to read/write to it.
Secondly, try not to use exec, system, or anything like that. Not only is it unsafe (passing args can be a real security hole), but it also adds a large overhead to the operation, having to spawn new sub-processes etc.
Also, using exec() just returns the last line of the command you run. If you really need to use a system program to perform functions then you should either use passthru() to return the data direct to the browser, or shell_exec() if you want to have the output in a string.