This expression is typically used to say that one should retaliate against an enemy using the same methods that one is attacked with. While it is counter intuitive to use fire to put out a fire in most cases the meaning of the expression doesn’t come from that. It is the fact that fire produces a powerful image in one’s head and using fire to fight fire can create an image of responding to an intense attack in the same way. My informant used the example of if someone spreads a bad rumor about you, you should in turn spread a rumor about them to fight back. This is an expression my informant has known about for as long as he can remember. They can’t necessarily remember a specific place where he learned it, just that he learned it.
Fighting fire with fire is an expression that has been around a long time. It is a folk metaphor as the expression applies to more than just putting out fires. While this may not be what people mean when they say this expression and it may be a bad in most cases the origin still may have come from a literal use of the phrase. Sometimes firefighters will burn certain areas in during a forest fire in order to cut off a fire so it will burn out. Thus they fight the larger fire that is a threat with a smaller easily controlled fire.