Is it OK to put serial.write in setup?

I'm not sure I understand the behavior here.

#include <Arduino.h>

void setup() {
    Serial.begin(115200);
    Serial.write(0x06);
    Serial.flush();
}

void loop() {
  char command;
    // put your main code here, to run repeatedly:
  if(Serial.available() > 0){
    Serial.print("FOOBAR");
    command=Serial.read();
    Serial.write(command);
  }
}

So I want to write an ACK byte when the serialport is ready, but randomly part of FOOBAR is written first. Does the loop async with setup? Does serial write to a buffer async? I thought flush would wait for that buffer to finish. Is my computer sending some rando bytes when the serial port is connected and is there a way to flush those first?

When I first connect to the serial port sometimes I see
"FOO"

with no ACK until I press a key

Sometimes I see "FOO"
and then ACK a second later

Sometimes I see "FOO<?>" with some unreadable character

Sometimes I see more or less of the whole word "FOOBAR"

I'm expect to only see ACK until I press a key(send something to the board)

I don't want the board to spit out anything, other than ACK

Why would there be something in Serial.available() when the board resets and is there a way to clear that in the setup function?

I'm using platformio's ide and serial monitor, but I've also tried connecting to the board straight through putty and screen and got the same behavior.

I think I understand what you're saying.
When I connect through putty or screen the board resets, but it might continue running the last few lines before it resets? Which says to me that connecting to the board must send some kind of ACK SYN sequence that triggers the FOOBAR loop.