Welcome to the site.
Couple of things to check.
Throttle position sensor(TPS), this is attached to the throttle plate rod opposite throttle cable linkage.
It has 3 wires
Top wire is 5volts from computer power supply, used by many sensors
Center wire is the "return voltage", tells computer where drivers foot is on gas pedal
Lower wire is a Ground
I use a sewing needle to pierce a wire to check its voltage while it is connected.
When key is on, engine off and throttle is closed, the center wire will show under 1 volt, .69v-.99v is spec.
As you manually open the throttle this voltage should increase steadily, no jumping around, when you get to WOT(wide open throttle) voltage should be above 4.5v, 4.55v-4.99v is spec
If you detect any jumping around, especially near closed throttle in your case, then TPS will need to be replaced.
If voltage jumps above 1volt then computer thinks YOU tapped the gas pedal, which can increase RPM, but................
Computer can only control Fuel flow with TPS data not air flow, and RPMs are generally controlled by air flow not fuel flow.
An engine is HELD at lower RPMs by choking off its air flow, the throttle plate.
The IAC(idle air control) valve is used to adjust the air flowing into the engine by-passing the throttle plate.
Computer controls the IAC Valve, this is needed on fuel injected engines because an idle screw wouldn't work.
IAC Valve is operated by an electric motor that turns to move a plunger type valve in and out to allow more or less air to by-pass throttle plate.
Computer uses IAC Valve to increase idle when engine is cold then lower idle as engine warms up and to increase idle a bit when AC is on.
If the plunger was sticking, and as RPM were getting lower the vacuum in the intake increases, this pressure could unstick the plunger causing it to open more, RPMs jump up, then computer closes plunger to set correct RPM, which would take a second or 2.
These are fairly easy to clean, 2 bolts to remove, and check that valve/plunger is not loose.