My sense is that NSCocoaErrorDomain is mapped to UNIX errno values, and errno 24 is "too many open files". Have a close look at the NSFileHandle class reference. Also,
[myHandle seekToEndOfFile];
[myHandle writeData:[str dataUsingEncoding:NSUTF8StringEncoding]];
[myHandle closeFile];
should be in the else case of your
if (!myHandle)
test.