The CMB is the snapshot of the decoupling of photons at 380.000 years , i.e. the photons stop hitting the mess of quark gluon etc and bouncing around, but escape without interactions from then on, just with the shift in frequency due to the expansion.Mass as we know it in the labs forms after that, originally with hydrogen.
The CMB is extremely uniform, and this uniformity cannot be thermodynamic. Have a look at another answer here. Nevertheless fluctuations appear at the level of 10^-5. The hypothesis in the standard Big Bang model is that after the infaltion period there existed accumulations of energy due to quantum fluctuations, which end up as seeds of the galaxies we see at our time. These are gravitionally bound energy, otherwise known as changes in space curvature which are embedded in space time, and expanded with the continuous expansion. The photons while decoupling, found more empty space at the flat sites of this curvature, and more of them go through to be registered at the CMB than from the direction of the tight space curvature locations which will evolve into galaxies and clusters of galaxies.
So the differences in energy density do not play a role, it is that the enegy density fluctuates that is recorded by the CMB photons.