替换文本文件PHP中的文本

Sorry if there are plenty of answers to this, but I tried EVERY Answer. I have a website (http://grmpixelmon.co/hwidreplace.html) there is the HWID Label where to input the HWID to replace in the text file (HWIDs.txt) but it keep giving me error 500.. here is the code I tried

<?php
// See the password_hash() example to see where this came from.
$hwid = $_POST['hwid'];
$FILE = "HWIDs.txt";
$replace = $_POST['replace'];
$replace_with = " ";
$password = $_POST['password'];
$password2 = 'mypassword';
if ($password2 === $password) {
    if ( empty ($hwid) ){
    echo 'you did not enter an hwid';
    }else{
        file_put_contents("HWIDs.txt", $hwid, FILE_APPEND);
        echo 'Succesfully added ';
        echo $hwid;
        echo ' as hwid';
    }
        $data = file_get_contents("HWIDs.txt");
$newdata = str_replace($replace, $replace_with, $data);
file_put_contents("HWIDs.txt", $newdata);
}
    }
} else {
    echo 'Invalid password.';

}
?>

Unless there is more code that you didn't include in the post then the curly braces are out of balance - a simple count of opening and closing or correct code indentation showed this.

$hwid = $_POST['hwid'];
$FILE = "HWIDs.txt";
$replace = $_POST['replace'];
$replace_with = " ";
$password = $_POST['password'];
$password2 = 'mypassword';


if ($password2 === $password) {
    if ( empty ($hwid) ){
        echo 'you did not enter an hwid';
    }else{
        file_put_contents("HWIDs.txt", $hwid, FILE_APPEND);
        echo 'Succesfully added ';
        echo $hwid;
        echo ' as hwid';
    }

    $data = file_get_contents("HWIDs.txt");
    $newdata = str_replace($replace, $replace_with, $data);
    file_put_contents("HWIDs.txt", $newdata);

} else {
    echo 'Invalid password.';
}