What are some common pitfalls when trying to output content on a separate file using PHP?

One common pitfall when trying to output content on a separate file using PHP is not properly handling file permissions. Make sure the file you are trying to write to has the correct permissions set to allow PHP to write to it. Additionally, make sure to close the file after writing to it to avoid any data loss.

<?php
$filename = 'output.txt';
$content = 'Hello, world!';

$file = fopen($filename, 'w') or die('Cannot open file');
fwrite($file, $content);
fclose($file);
?>