This is an extremly inefficient implementation. It creates random permutations by the (slow) RANDPERM in an infinite loop (for i=1:inf). Then inn a FOR loop it is checked, if the perumtation is stored already. For n=10 this takes ages.
Beside Matlab's RANDPERM you find several more efficient solutions in the FEX.