By storing the chemicals in separate chambers the two potential reactants can be kept apart, avoiding damage to the organism. The beetle probably allows them to mix in a chamber which is chemically resistant and separated from the rest of the organism. The strong and exergonic reaction of the two chemicals leads to boiling, with the gas produced causing the explosive discharge.
Work Step by Step
The key here is to see the difference between two reactants and what can happen when they react, with energy released and potential damage resulting.