Another way to approach could be
Ignore the last (nth) element.
The remaining (n-1) elements can be de-arranged in D(n-1) ways, once you do that the nth element can interchange place with any of the (n-1) element to give you a de-arrangement of n elements.
Also, out of the (n-1) element we can have an element which holds its poisition, say element 'i'. Other element (remaining (n-2) elements) can be de-arranged in D(n-2) ways. Once this is done to get de-arrangement of 'n' elements you just interchange positions of ith and nth element. Now, i can take values from 1 to (n-1).
You can see immdiately that no more than 1 of the (n-1) elementss can hold its position. So above two exhaust all the cases for D(n). Hence
D(n) = (n-1).D(n-1) + (n-1)D(n-2)