in reply to Unwanted extra text appearing in array
Your problem is probably in the output from the method call to cmd();
Try piping the output from that command directly to a file and take a look at it.
Make sure you're getting what you expect.
(Not really very helpful)
-muoyo