DownloadFileOnAgent not working for large files

I am having a file of size approx. 25 MB on s3. While saving the file on node, the downlaodFileOnAgent() method is throwing exception. If the file size is 1 or 2 MB then it is working properly. Is there any limitation on the file size upto which we can use download file from agent?
In another approach I tried to put the file on node using executegroovyscript() and there I am getting JAVA HEAP SPACE.

Please assist.