The code looks OK so I suspect a hardware problem. nCommon servo mistakes are:
- Using the Arduino's +5V pin to power the servo (the servo can cause the Arduino to reset)
- Using an external power supply for the servo but forgetting to connect the negative side of that supply to the Arduino Ground.