Jesse seems to have covered it. Sometimes one may be more appropriate than the other but I can't think of any examples. I found this example online that seems to distinguish between their uses:
What is the difference in meaning between these sentences?
A. Why did you do that?
B. What did you do that for?
There is HUGE difference. Sadly, most people do not know that rule.
"Why" asks for the cause, while "what for" asks for the effect.
Here is an example:
Assume that I am slicing some chicken.
- Why are you slicing some chicken?
- Well, the breast was whole (cause) so I am slicing it (effect).
- What are you slicing some chicken for?
- I am slicing some chicken (cause) to make stir fry (effect).