Register visits of my pages in wordpresss

I have a shortcode that obtains the name of the person logged into wordpress, I would like that shortcode when the person enters a page where I have my shortcode create a .text file and save their name inside it

this is my wordpress shortcode

function alertaLogin( $  atts ) {     global $  current_user, $  user_login;     wp_get_current_user();     add_filter('widget_text', 'apply_shortcodes');     if ($  user_login)         return 'hola ' . $  current_user->display_name;     else         return 'no ha iniciado session'; }  add_shortcode( 'shortcode_login', 'alertaLogin' );   $  contenido = 'saludo'; $  archivo = fopen('archivo.txt','a+'); fputs($  archivo,$  contenido); fclose($  archivo); 

How can I create a .txt from this shortcode to store data within it ???