The issues you should consider when weighing this are portability, speed of development, and efficiency.
If you build functionality into your script instead of relying on an external process, your script should run easily on different platforms or on systems that don't include the third-party application you would be calling. For simple tasks (such as obtaining a directory listing), handling the problem within your code is probably more efficient, saving you the overhead of spawning a second process every time your script is called.
On the other hand, some tasks can be difficult to achieve in PHP or slow to complete (grepping a large file, for example). In these cases, you might need to use a tool specifically designed for the job.