Aims. We study the 2D spectral line profile of HARPS (High Accuracy Radial Velocity Planet Searcher), measuring its variation with position across the detector and with changing line intensity. The characterization of the line profile and its variations are important for achieving the precision of the wavelength scales of 10^{-10} or 3.0 cm/s necessary to detect Earth-twins in the habitable zone around solar-like stars. Methods. We used a laser frequency comb (LFC) with unresolved and unblended lines to probe the instrument line profile. We injected the LFC light (attenuated by various neutral density filters) into both the object and the reference fibres of HARPS, and we studied the variations of the line profiles with the line intensities. We applied moment analysis to measure the line positions, widths, and skewness as well as to characterize the line profile distortions induced by the spectrograph and detectors. Based on this, we established a model to correct for point spread function distortions by tracking the beam profiles in both fibres. Results. We demonstrate that the line profile varies with the position on the detector and as a function of line intensities. This is consistent with a charge transfer inefficiency (CTI) effect on the HARPS detector. The estimate of the line position depends critically on the line profile, and therefore a change in the line amplitude effectively changes the measured position of the lines, affecting the stability of the wavelength scale of the instrument. We deduce and apply the correcting functions to re-calibrate and mitigate this effect, reducing it to a level consistent with photon noise.