The effect of wiggler imperfections on nonlinear harmonic generation in free-electron lasers