Replace tempnam with mktemp.
Change to NSMutableArray
Replace tempnam().
Why was a folder being created? Doesn't seem necessary.