Plugin Generate Unexpected output during activation

It is bad practice to end a PHP only file with the PHP closing tag (?>) as it may lead to a new line or any other character being output before the headers or other functions and thus creating problems like the one you mention.

Whenever you create/edit a PHP file, don’t close it, if you have to include HTML, close and open the PHP tags again.

https://php.net/basic-syntax.instruction-separation

The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include or require, so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.

Best regards.