The percentage of dark matter as a fraction of the energy content of the universe is determined by fitting the standard model of cosmology, the Lambda-CDM model, to precise observations of the anisotropies of the temperature of the cosmic microwave background. The most recent value of 25.89% comes from observations done by the European Space Agency’s Planck spacefraft from 2013 to 2015. The instruments on this spacecraft were capable of measuring the CMB temperature to just a few parts per million!
As for why dark matter and ordinary matter affect the CMB differently, Wikipedia’s “Dark matter” article explains:
“Although both dark matter and ordinary matter are matter, they do not behave in the same way. In particular, in the early universe, ordinary matter was ionized and interacted strongly with radiation via Thomson scattering. Dark matter does not interact directly with radiation, but it does affect the CMB by its gravitational potential (mainly on large scales), and by its effects on the density and velocity of ordinary matter. Ordinary and dark matter perturbations, therefore, evolve differently with time and leave different imprints on the cosmic microwave background (CMB).”
Your idea that dark matter and ordinary matter would behave differently gravitationally is incorrect: the model assumes that they are identical gravitationally. It is the fact that ordinary matter has electromagnetic interactions, while dark matter does not, that distinguishes their effects.