If there is a bad spot on the sensor, lets say when the fuel level gets to 1/4 full, the snesor may have a open circuit, when you fill the tank, the sensor moves due to the float in the tank, this then makes the sensor read correctly again. The reason this will set off a check engine light is due to the engine computer performs a evap leak test for the fuel system (the computer checks for leaks in the fuel tank such as the fuel cap). The computer can only run this test when the fuel level is between 3/4 and 1/4 full. If the fuel level sensor is going bad, then te engine computer does not know how much fuel is really in te tank which can affect the test results.
This is only a possiblity and unless the code P0463 is set, then this is only a guess.
DTC P0463 Fuel Level Sensor Circuit High Voltage
The vehicle control module (VCM) requires an accurate indication of fuel level for evaporative emission (EVAP) system diagnosis. The fuel level in the fuel tank changes the rate of vacuum decay for the EVAP system leak DTCs.
The fuel level sensor changes resistance based on fuel level. The fuel level sensor has a signal circuit and a ground circuit. The VCM applies a voltage of about 5 volts on the signal circuit to the sensor. The VCM monitors changes in this voltage caused by changes in the resistance of the sensor to determine fuel level.
When the fuel tank is full, the sensor resistance is high, and the VCMs signal voltage is only pulled down a small amount through the sensor to ground. Therefore, the VCM will sense a high signal voltage (fuel tank full). When the fuel tank is empty, the sensor resistance is low, and the signal voltage is pulled down a greater amount. This causes the VCM to sense a low signal voltage (fuel tank empty).
The VCM uses the input from the fuel level sensor to calculate the fuel level in the fuel tank. This information is then sent to the IPC through Serial Data.
The diagnostic will not run when the tank is more than 85 percent or less than 15 percent full. (This sensor signal disables the misfire when the fuel levels are less than 15 percent).