So how is "the lesser of two evils" any different from "the end justifies the means"? You do something wrong because the outcome is better, right?
One can argue that the examples you cite from Harry Potter are examples of "the lesser of two evils", as well - lying versus aiding the evil side, breaking rules to save lives, etcetera.
The principle of "the lesser of two evils" means that a person can only choose between two things, both of which are evil. Choosing the lesser evil is the proper moral choice.
The principle of "the ends justifying the means" is choosing to do evil in order that good may come. An example would be me stealing a car from a man with two cars and giving it to my friend who doesn't have a car.