How to get the image from the url and store in the custom path?
Hope this will help you.

In Drupal 7 , system_retrieve_file function will download a file from a remote source, copy it from temp to a specified destination and optionally save it to the file_managed table if you want it to be managed.


You need to create a folder beachesmigration inside sites\default\files.
By using system_retrieve_file it will be store your images inside beachesmigration folder with the filename you no need to specify the filename manually.



 $image = 'http://wordpress.ikitesurf.com/wp-content/uploads/2012/09/2032239599_fdce5e0ab0_z.jpg';
//I have used picture folder to store images using image field settings
 $file = system_retrieve_file($image, 'public://beachesmigration/', TRUE, $replace = FILE_EXISTS_REPLACE);



Source