Very simple code:
<?php
$last_line = system('pwsh -Command (Get-Location).path', $retval);
Returning string on html page:

How is this possible and how to avoid it?
>Solution :
The PHP system() command executing a system command and print immediately the output out. To avoid that you can use exec().