Impact of electron beam quality on nonlinear harmonic generation in high-gain free-electron lasers