We present a new catalogue of ~2,400 optically selected quasars with spectroscopic redshifts and X-ray observations from either Chandra or XMM-Newton. The sample can be used to investigate the non-linear relation between the UV and X-ray luminosity of quasars, and to build a Hubble diagram up to redshift z~7.5. We selected sources that are neither reddened by dust in the optical/UV nor obscured by gas in the X-rays, and whose X-ray fluxes are free from flux-limit related biases. After checking for any possible systematics, we confirm, in agreement with our previous works, that (i) the X-ray to UV relation provides distance estimates matching those from supernovae up to z~1.5, and (ii) its slope shows no redshift evolution up to z~5. We provide a full description of the methodology for testing cosmological models, further supporting a trend whereby the Hubble diagram of quasars is well reproduced by the standard flat $Lambda$CDM model up to z~1.5-2, but strong deviations emerge at higher redshifts. Since we have minimized all non-negligible systematic effects, and proven the stability of the $L_{rm X}-L_{rm UV}$ relation at high redshifts, we conclude that an evolution of the expansion rate of the Universe should be considered as a possible explanation for the observed deviation, rather than some systematic (redshift-dependent) effect associated with high-redshift quasars.