The file named in the cmd command could not be opened, either because the maximum number of files was already open, or because you were not permitted to write to file.
Either simplify your script, so that it requires fewer open files, or check to ensure that you do have permission to write to the file.