If you are going to store a password in a text file, I suggest encrypting it with the sha1() function.
After getting permissions sorted out, you might want to try something like this:
<?php
$newpass = sha1('new pass');
$file = 'password.txt';
if(!file_exists($file))
{
echo 'The file, ' . $file . ', does not exist';
exit;
}
else {
if($fp = fopen($file, 'w'))
{
// saving data
$write = fwrite($fp, $newpass);
$close = fclose($fp);
if($write)
{
echo 'Success. New password was written to: ' . $file;
}
}
else {
echo 'Could not create a file pointer.';
exit;
}
}
?>