New line removed from core config file after snap set

Running the test main/snapctl-configure-core on pi 2 and 3 there is a failure running this piece of code:

echo "Check that pi config handline works"
if [ -e /boot/uboot/config.txt ]; then
    cp /boot/uboot/config.txt

    snap set core pi-config.hdmi-mode=1
    cat /boot/uboot/config.txt | MATCH ^hdmi_mode=1
    snap set core pi-config.hdmi-mode=""
    cat /boot/uboot/config.txt | MATCH ^#hdmi_mode=1

    echo "Ensure the config.txt are fully undo when an option is unset"
    if ! diff -u /boot/uboot/config.txt; then
        echo "error: unexpected diff in /boot/uboot/config.txt"
        exit 1

Basically, what it is happening, is that the file /boot/uboot/config.txt does not contains a new line at the end of the file as it had initially, and it makes the diff to fail.

The error obtained

It works properly on vms running ubuntu core, but it fails on boards.