What are the potential pitfalls of including PHP tags in a file using fwrite() and fclose() functions?

Including PHP tags in a file using fwrite() and fclose() functions can lead to syntax errors or unexpected behavior when the file is executed as PHP code. To avoid this issue, it's recommended to write the PHP code to the file without including the PHP tags.

$file = fopen('example.txt', 'w');
fwrite($file, 'Hello, world!');
fclose($file);