A 1996 and newer car will store all trouble codes in memory until the ECU completes either 2 or 3 trips (depending on the fault) without seeing the same fault again. With that said, if your car's check engine light is intermittently turning on chances are the trouble code which is causing the check engine light to tun on and off is still within memory and upon getting hooked up to the smog machine this information will be transferred to the machine; your vehicle will fail the smog check even with the check engine light off.
Our recommendation is to find out what is causing the check engine light to illuminate and repairing the fault prior to the next smog check.