Different behavior of the sketch if Arduino is powered by battery

I' m relatively new on
Arduino, but I know a project that uses, like as me, that battery to power on Arduino using the Vin line and controls the servo with the digital pin 3. https://www.instructables.com/Servo-Motor-Car-With-Arduino/.
P.S: I' m attempting to realize the same project with the same hardware and starting from the same code.