Different behavior of the sketch if Arduino is powered by battery

Which Arduino?

What is voltage you used on Vin pin?