What are some potential pitfalls of using .txt files for storing guestbook entries in PHP?

One potential pitfall of using .txt files for storing guestbook entries in PHP is that it can be vulnerable to security risks such as injection attacks. To mitigate this risk, it is important to properly sanitize and validate user input before writing it to the file. Additionally, using a database to store guestbook entries can provide better security and scalability.

// Sanitize and validate user input before writing to the file
$entry = filter_var($_POST['entry'], FILTER_SANITIZE_STRING);

// Open the file in append mode and write the entry
$file = fopen('guestbook.txt', 'a');
fwrite($file, $entry . PHP_EOL);
fclose($file);