Translation:This is the friend to whom I have given the key.
It should have been marked correct, but the preposition rule is actually borrowed from Latin and foisted (relatively recently) on English, a Germanic language, in which it is an unnatural and artificial construction. That's why it sounds pedantic to say "to whom I have given," and why the spoken language usually puts the preposition at the end, rather than contorting itself to follow a Latin rule. The issue is that Latin was thought to be better and more "logical" than English. That's silly, though, and in any case, all languages are "logical" - they have their own rules and function by them; if they were not inherently "logical" they could not function at all. Linguistically speaking, there is nothing wrong at all with ending with a preposition in English. The Scandinavian languages (much closer relatives to English than Latin is) do it all the time. But yes, putting the preposition at the end should not have lost you a heart.