Added at top:
Your code runs correctly on a $US3 Arduino Nano :-)
It seems extremely likely that you have a hardware problem of some sort.
If you have a voltmeter you can try these easy checks.
I carried these out to be sure that I got what was expected and the results are as you would expect them to me. Use a meter set to DC Volts - typical common meter circuitry averages the PWM well.
Remove LED etc connection to pin 9.
Measure the voltage from the 5V pin to ground. If powered from USB this will usually be slightly below 5V.
Run your code with the analogWrite set to 128 ie
Measure the voltage on pin 9 relative to ground. It should be close tohalf the voltage on the 5V pin in 1. above. This is because the analogWrite value is controlled by PWM with values from 0 to 255. 128/255 ~= 50% so output is 50% of Vref = 5V by default. in a 5V system.
Set analogWrite to
The voltage on pin9 should be about 10% of the voltage on the 5V pin.
IF you get approximately the voltages shown in 3. and 5. your code is working OK and your hardware is OK. If not then 'summat aglae'.
Try another analog pin.
Check that the red wire to the LED goes to UNO ground.
The voltmeter is a surer way of checking that the LED is as you can see actual numeric values that result.
It always helps greatly if you show PIN IDs on photos so people can be confident re what you have done.
If you view the whole UNO-R2-R3 connector with numbering it is obvious that the important pinouts are the same.
If however you view part of the connector with no numbering/ pin names shown, then on the R3 there are additional pins on the ARef end of the connector which make comparisons'more difficult).
You APPEAR to have an Arduino UNO R3
It would help if you gave actual model and weblink in future "just in case it matters". .
You appear to have connected to pin 9 (as you intended to)
Pin 9 has PWM capability, as required.
It seems that your code should work.
IF the red wire connects to ground the circuit seems electrically correct.
Code LOOKS OK.
Try digital write on / off on pin 9 to see if LED changes and that the port behaves as expected. A bad port pin is possible.
What pin is serial on?
Try another pin with PWM capability to see if it changes.
ARDUINO UNO R3 from UNO home page
The connector pinouts vary widely between models of UNO.