Arduino - Pulses get unstable when updating PWM duty-cycle
Could be because your variable 'val' does get different values. Because usually when you have a closed loop system the LSB's toggle even though the final value  stabilizes. Even if yours is not a closed loop system I think by just logging 'val' first and checking the values must give a clue. Because if 'val' changes then its correct that your duty also changes with it. 

Because in your second case you have the same code but it does not jitter which means that the arithmetic operations are not causing the jitter. I therefore think if you log the data (print the data continuously and see the value of 'val') it would be helpful or at least directing you in finding the right solution.