The files in /sys/ are actually kernel drivers, much like in /proc/. Those file-based drivers are rather simple-minded and desigend to use by shell scripts, where each echo foo > /proc/some/magic/file ends in calling open(2), write(2), and close(2). So you should simulate that behaviour.
I completely forgot to mention that perl and/or the C library try to AVOID writing files, because writing files is slow (compared to writing to RAM). So, there is at least one layer of caching between your program and the kernel drivers. That cache needs to be flushed for the kernel drivers to see your program writing to the virtual files. Simply closing the file handle is the easiest way to do that. $| (autoflush) would probably also work. But as shown, just closing the file also avoids having unused file handles lingering around.
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)