You could save these results in a JSON array.
<?php
//Start the session
session_start();
//Include connection
include 'connessione.php';
//Get user ID
$id = $_SESSION['id'];
//Query to get stuff from database
$query_string = "SELECT * FROM utenti ORDER BY id DESC LIMIT 50";
$query = mysqli_query($connessione, $query_string);
//Get results
$results = mysqli_fetch_assoc($query);
//Make that into a JSON array
$results = json_encode( $results );
//Put those results in a file (create if file not exist)
$fileName = 'backup_file_' . time() . '.txt';
$file = fopen( $fileName , 'a' );
fwrite( $file, $results );
fclose( $file );
//Delete the rows that you just backed up
$query_delete = "DELETE FROM utenti ORDER BY id DESC LIMIT 50";
mysqli_query( $connessione, $query_delete );
?>
for example, if your table looks like this:
| id | name | email_address |
|----+------+---------------|
| 1 | dave | dave@test.com |
| 2 | emma | emma@test.com |
| 3 | mark | mark@test.com |
+----+------+---------------+
your backup file will look like this:
[{"id":1,"name":"dave","email_address":"dave@test.com"},{"id":2,"name":"emma","email_address":"emma@test.com"},{"id":3,"name":"mark","email_address":"mark@test.com"}]