When I open a COM port some pins on Arduino Uno goes low for about 2 seconds I have no idea why this is happening, but after I open COM port to talk with my Arduino (I click "Open" in RealTerm), the state of some pins goes from high to low for about 2 seconds and then goes back to high. Here's my code:

void setup()
{
  pinMode(5, OUTPUT);
  digitalWrite(5, HIGH);
  Serial.begin(9600);
}

void loop()
{
}


In this case pin 5 will behave this way. I've checked it also for pin 6 and pin 8 and they behave in the same manner. I suppose more pins act like that. Why is this happening?
What you see is expected: that's because opening the USB connection to the UNO will automatically trigger a reset of the ATmega chip of the board, hence your sketch will be executed from scratch, ie setup() will be called again then your loop() repeatedly.

Hence what you observe in detail:


open USB connection from PC
open USB connection on Arduino UNO
UNO USB chip (an ATmega16u2) triggers a RESET of the MCU (an ATmega328P-PU)
On reset, the MCU sets all pins to INPUT, i.e. high impedence, hence no voltage can be measured on any pin
Then the bootloader starts, performs some intialization and starts your sketch
Your sketch executes first setup(), so your pin is put in OUTPUT mode and set to HIGH: its voltage is thus measurable (5V)
your sketch loop() gets executed "forever" i.e.until a new reset or power supply disconnection