How to fix this servo code

Analog write technically only goes up to 255,

Unless you're on a Due, there's no "technically" about it, and the sooner you convince yourself of that, the happier we'll all be.
If you want a sawtooth, keep using 0..1023, otherwise use 0..255.