implemented a function that saves extracted image to a file