Added try finally for writing file
Updated logging with info about number of bytes