Tiny function to write array or string to a file for testing with MVC, Ajax, etc
Mixing fwrite and file_put_contents usage is a little strange, as they are functions which overlap in functionality. file_put_contents in fact is just a wrapper to call fopen, fwrite and fclose - expanding that call to it's component parts would therefore make what the code is doing more obviously repetitive. 

So, the first goal I would suggest is to avoid repeatedly opening the file to append text to it; the goal of the function is simply to append bytes to a file - so make the function do that, in one write call. An example of what I mean is:

function write_to_file($message)
{
    $header = "\nMessage:\t ";

    if (is_array($message)) {
        $header = "\nMessage is array.\n";
        $message = print_r($message, true);
    }

    file_put_contents(
        '/path/to/logs/a_log_file.php', 
        $header . $message, 
        FILE_APPEND | LOCK_EX
    );
}