Why would I do that?
Why would I have done that?
as far as I think why would I do that implies my friend's accusing me of doing something that I didn't do So I'd say Why would I do that? (what reason I had to do that)
2nd case (why would I have done that) If it's clear that I haven't done that
the other person knows it then I'd say why would I have done that (would have implies that it never happened but if it did what would be the reason. or what would have been the reason if I had done that)