Arduino Leonardo timing Inconsistency
There is only a very slight chance that you meet the holdDuration &gt;= 4000 condition in the while loop. Only when holdDuration will be exactly 4000 the while loop will be executed AND the subsequent test in the if statement will pass.

The serial print commands can easily take long enough to have millis() jump from a number less than 4000 to a number higher than 4000 in a single pass of the while loop.

To prove this assumption, increase the while test to holdDuration &lt;= 4100 and see if the intermittent effect goes away.