Random button presses

should be
unsigned long previousMillis = 0;

should be
previousMillis += 50;
As that is the timer window you need to maintain.

I don't think that would effect debounce though.

I think the issue is between val, old_val, and buttonstate.