This function provides approx. 10x speed up on a windows machine as compared to imwrite(..'append') loop. But, on mac (I presume also on Unix) the call to fileattrib (fileattrib(tempfile, '+h +w', '', 's');) throws an exception. saveastiff catches this exception and deletes the temp file without saying anything.
The exception occurs because +h (hidden) attribute is not valid on mac. Removing +h and -h from the calls to fileattrib fixes the problem.