Why can't write info into /tmp directory instead of /var/www/html?

You are not sharing with us the return of file_put_contents("/tmp/test",$str);, but I'm going to assume that you are actually writing the appropriate bytes.

Being that the case, and considering the permissions look OK and that you don't say that are getting an error message, the most likely scenario is a problem with systemd configuration.

Your Apache/PHP process are writing to that location correctly, but systemd has a configuration setting that allows for each process to have its own /tmp directory.

PrivateTmp=
    Takes a boolean argument. If true sets up a new file system
     namespace for the executed processes and mounts a 
     private /tmp directory inside it, that is not shared by     
     processes outside of the namespace. This is useful to secure 
     access to temporary files of the process, but makes sharing
     between processes via /tmp impossible. 

Defaults to false.

In this case, the tmp you see as a regular or root user is not the same tmp directory that apache/php sees. Read more about this here, for example.

You could disable the PrivateTmp setting for Apache, but I think it would be easier to choose a different path to store your files, and give the apache/PHP process permission to write there.

There could be other possible explanations for not being able to write to tmp despite the directory permissions: e.g. that that directory was not added to the open_basedir directive, or that somehow the directory immutable attribute got set (very unlikely for /tmp). But in any of these cases, you would be getting an error message.