Why aren't all planets in the same plane? Obviously all planets are not in same perfect plane. Because if at all they were in the exact same plane, it would mean that Mercury transits and Venus transits would not be that rare.

Any explanation would be much appreciated.
Your reasoning is correct: if Mercury orbited in the same plane as Earth, we'd see it transit the Sun every 4 months or so. In fact these orbital planes are inclined 7 degrees to each other, and the other major planets' orbits are inclined 1 to 3 degrees relative to Earth's.

The planets perturb each other's orbits slightly, so no planet's orbit is perfectly planar.
However, the Solar system average plane of all orbits and rotations is
invariable,
and most individual planets' orbits will remain near it for millions of years.