You can set the output transform using the source dataset window_transform
method:
etc...
window = int(width*i/grid_size), int(height*j/grid_size), grid_width, grid_height
transform = file.window_transform(window)
profile.update({'transform': transform})