Bool setting with If statements

Hi, I am not a super versed C/C++ developer, I know enough to just get some basics going, but have hit a simple issue I cannot figure out. I am currently running a simple sketch that watches for a HIGH/LOW pin value every 10 seconds. I then want to keep a Bool value to capture if it's HIGH or LOW so that I do not print the Serial statement every 10 seconds if the pin stays HIGH for a long time. Essentially I just want one Print for On or Off ONLY when the pin changes. Also, the pin will not change more frequently than 10 seconds, so assume it is not changing between delayed checks.

Basic code below. What I am finding is that I get HIGH and LOW showing sequentially in some cases, I would expect with my if statements that I should never be able to get the same case in a row. I assume I am not trapping properly with my if statement, or there is likely a much better way to do this that someone could offer? It should be noted, each change on the pin is happening around every 3-4 minutes, and the Serial print happens as expected when the Pin does change, just the value is wrong as shown in the results below. Any advice appreciated, thank you!

Current results:

Pin is HIGH!
Pin is LOW.
Pin is HIGH!
Pin is HIGH!
Pin is HIGH!
Pin is LOW.
Pin is LOW.
...

Sketch code:

bool pinHIGH = false;

void setup() {
  Serial.begin(115200);
  pinMode(5, INPUT);
}

void loop() {
  // Check if Pin is HIGH
  if (digitalRead(5) == HIGH && !pinHIGH) { 
    Serial.println("Pin is HIGH!");
    pinHIGH = true;
  } 
  // Check if Pin is LOW
  else if (digitalRead(5) == LOW && pinHIGH) { 
    Serial.println("Pin is LOW.");
    pinHIGH = false;
  }
  delay(10000); // Wait 10 sec to check again
}

Search for debounce.

Or use:

pinMode(5, INPUT_PULLUP);

Great, thanks for the pointer, will dig into it!

byte pinChanged, input, inputLast;

pinChanged = (input ^ inputLast);
inputLast = input;